--[[
	Project:		TruRP
	Author:			Martin 'Ploo' Pucilowski
	File:			cl_hud.lua
	Date:			02/2010
	Description:	Handles all of HUD
--]]

--surface.CreateFont( String font_name, Number size, Number weight, Boolean antialiasing, Boolean additive, String new_font_name )
surface.CreateFont( "TargetID", 20, 400, true, false, "BigTargetID" )
surface.CreateFont( "TargetID", 16, 400, true, false, "MedTargetID" )
surface.CreateFont( "TargetID", 12, 400, true, false, "SmallTargetID" )

hook.Add("HUDPaint", "DrawTruRPHUD", function()
	DrawPlayerHUD()
end )

function DrawPlayerHUD()
	local ply = LocalPlayer()

	--if !ply:Alive() then return end
	if(ply:GetActiveWeapon() == "Camera") then return end

	local HUD = {  }
	HUD.W = 256
	HUD.H = 90
	HUD.X = 8
	HUD.Y = 8
	HUD.Font = "ScoreboardText"
	HUD.Color = Color(255,255,255,255)
	HUD.ColorOutline = Color(0,0,0,255)

	draw.RoundedBox(8, HUD.X, HUD.Y, HUD.W, HUD.H, Color(0,0,0,200))
	draw.RoundedBox(8, HUD.X+1, HUD.Y+1, HUD.W-2, HUD.H-2, team.GetColor(ply:Team()))
	draw.SimpleTextOutlined("Name: " .. ply:GetNWString("RPName"), HUD.Font, HUD.X + 8, HUD.Y + 4, HUD.Color, TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT, 1, HUD.ColorOutline)
	draw.SimpleTextOutlined("Money: " ..  ply:GetNWInt("Money"), HUD.Font, HUD.X + 8, HUD.Y + 20, HUD.Color, TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT, 1, HUD.ColorOutline)
	draw.SimpleTextOutlined("Health: " .. ply:Health(), HUD.Font, HUD.X + 8, HUD.Y + 36, HUD.Color, TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT, 1, HUD.ColorOutline)
	draw.SimpleTextOutlined("Armor: " .. ply:Armor(), HUD.Font, HUD.X + HUD.W / 2, HUD.Y + 36, HUD.Color, TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT, 1, HUD.ColorOutline)
--	draw.SimpleTextOutlined("Occupation: " .. Occupations[ply:Team()].Name, HUD.Font, HUD.X + 8, HUD.Y + 52, HUD.Color, TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT, 1, HUD.ColorOutline)
	draw.SimpleTextOutlined("Time: " .. GetRPTime() .. " Date: " .. GetRPDate(), HUD.Font, HUD.X + 8, HUD.Y + 68, HUD.Color, TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT, 1, HUD.ColorOutline)

end

function HUDDrawDoorInfo()
	local ply = LocalPlayer()
	local door = ply:TraceDoor()
	if not door then return end
	
	local HUD = {  }
	HUD.Font = "ScoreboardText"
	HUD.X = ScrW() / 2
	HUD.Y = ScrH() / 2
	HUD.Color = Color(255,255,255,255)
	HUD.ColorOutline = Color(0,0,0,255)

	if door:GetNWString("PropertyTitle") then
		--surface.SetFont("BigTargetID")
		draw.SimpleTextOutlined(door:GetNWString("PropertyTitle"), "BigTargetID", HUD.X, HUD.Y, HUD.Color, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, HUD.ColorOutline)
	end
	if door:GetNWString("DoorTitle") then
		--surface.SetFont("MedTargetID")
		draw.SimpleTextOutlined(door:GetNWString("DoorTitle"), "MedTargetID", HUD.X, HUD.Y + 24, HUD.Color, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, HUD.ColorOutline)
	end
	
	if door:GetNWInt("PropertyType") == PROPERTY_RENTABLE then
		draw.SimpleTextOutlined("Press F4 to Rent", "SmallTargetID", HUD.X, HUD.Y + 48, HUD.Color, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, HUD.ColorOutline)
	elseif door:GetNWInt("PropertyType") == PROPERTY_PUBLIC then
		draw.SimpleTextOutlined("Unownable", "SmallTargetID", HUD.X, HUD.Y + 48, HUD.Color, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, HUD.ColorOutline)
	elseif door:GetNWInt("PropertyType") == PROPERTY_ADMINISTRATION then
		draw.SimpleTextOutlined("City Administration Only", "SmallTargetID", HUD.X, HUD.Y + 48, HUD.Color, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, HUD.ColorOutline)
	end
end




function GM:HUDDrawTargetID()
	local ply = LocalPlayer()
	local ent = ply:GetEyeTrace().Entity
	if not ValidEntity( ent ) then return end
	
	-- Is it a player?
	if ent:IsPlayer() then
		local text = "ERROR"
		local font = "TargetID"
		
		surface.SetFont( font )
		local w, h = surface.GetTextSize( text )
		
		local MouseX, MouseY = gui.MousePos()
		
		if ( MouseX == 0 && MouseY == 0 ) then
			MouseX = ScrW() / 2
			MouseY = ScrH() / 2
		end
		
		local x = MouseX
		local y = MouseY
		
		x = x - w / 2
		y = y + 30
		
		// The fonts internal drop shadow looks lousy with AA on
		draw.SimpleText( text, font, x+1, y+1, Color(0,0,0,120) )
		draw.SimpleText( text, font, x+2, y+2, Color(0,0,0,50) )
		draw.SimpleText( text, font, x, y, self:GetTeamColor( trace.Entity ) )
		
		y = y + h + 5
		
		local text = trace.Entity:Health() .. "%"
		local font = "TargetIDSmall"
		
		surface.SetFont( font )
		local w, h = surface.GetTextSize( text )
		local x = MouseX  - w / 2
		
		draw.SimpleText( text, font, x+1, y+1, Color(0,0,0,120) )
		draw.SimpleText( text, font, x+2, y+2, Color(0,0,0,50) )
		draw.SimpleText( text, font, x, y, self:GetTeamColor( trace.Entity ) )
	end
	
	if ent:IsDoor() then
		HUDDrawDoorInfo()
	end
	
	-- Is it an item?
	if ent:IsItem() then
		if not ply:CanTraceEntity( ent, 96 ) then return end
		if not ValidWorldItem( ent ) then return end

		local HUD = {  }
		HUD.Name = GetItem( ent.Item.Class ).Name
		HUD.Font = "ScoreboardText"
		HUD.X = ent:GetPos( ):ToScreen( ).x
		HUD.Y = ent:GetPos( ):ToScreen( ).y
		HUD.Color = Color(255,255,255,255)
		HUD.ColorOutline = Color(0,0,0,255)
		
		draw.SimpleTextOutlined(HUD.Name, HUD.Font, HUD.X, HUD.Y, HUD.Color, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, HUD.ColorOutline)
	end
end

hook.Add("HUDShouldDraw", "HideHUD", function( name )
	--hideHUD = { "CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo" }
	local hideHUD = { "CHudHealth", "CHudBattery" }
	for k, v in pairs( hideHUD ) do
		if name == v then return false end
	end
end )